package cc.linker.steplink.crm.commons.utils;

import java.util.Map;
import java.util.Random;
import java.util.Set;

/**
 * @Description: 该类的描述定义、使用范围
 * @Author:
 * @Date: Created in 2019/10/15 14:47
 * @Version:
 */
public class StringUtil {
    /*
     *获取随机字符串
     */
    public static String getRandomString(int length){
        String randomKey="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer(length+1);
        for (int i=0; i < length; i++){
            int number = random.nextInt(randomKey.length());
            stringBuffer.append(randomKey.charAt(number));
        }
        return stringBuffer.toString();
    }

    public  static  String getStringByMap(Map<String, Object> map) {
        String result = "";
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            result += key + "_" + map.get(key) + "_";
        }
        return result.substring(0, result.length() - 1);
    }
}
